home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / var / lib / python-support / python2.6 / orca / dectalk.pyc (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2009-04-20  |  12.0 KB  |  365 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. '''Dectalk voice definitions using ACSS.
  5.  
  6. This module encapsulates Dectalk-specific voice definitions.  It
  7. maps device-independent ACSS voice definitions into appropriate
  8. Dectalk voice parameter settings.
  9.  
  10. '''
  11. __id__ = '$Id: dectalk.py 4281 2008-10-08 22:05:56Z wwalker $'
  12. __author__ = 'T. V. Raman'
  13. __version__ = '$Revision: 4281 $'
  14. __date__ = '$Date: 2008-10-08 18:05:56 -0400 (Wed, 08 Oct 2008) $'
  15. __copyright__ = 'Copyright (c) 2005-2008 Google Inc.'
  16. __license__ = 'LGPL'
  17. import chnames
  18.  
  19. def makeSpecialCharMap():
  20.     '''Returns list of pairs mapping characters which are special for
  21.     Dectalk speech server to their replacements.
  22.     '''
  23.     chars = '{\\}[]'
  24.     return [ (ch, ' ' + chnames.getCharacterName(ch) + ' ') for ch in chars ]
  25.  
  26. _defined_voices = { }
  27. _table = { }
  28. _table['family'] = {
  29.     'male': ' :np ',
  30.     'paul': ':np',
  31.     'man': ':nh',
  32.     'harry': ' :nh ',
  33.     'dennis': ':nd',
  34.     'frank': ':nf',
  35.     'betty': ':nb',
  36.     'female': ' :nb ',
  37.     'ursula': ':nu',
  38.     'wendy': ':nw',
  39.     'rita': ':nr',
  40.     'kid': ':nk',
  41.     'child': ' :nk ' }
  42.  
  43. def _update_map(table, key, format, settings):
  44.     '''Internal function to update acss->synth mapping.'''
  45.     table[key] = { }
  46.     for setting in settings:
  47.         _table[key][setting[0]] = format % setting[1:]
  48.     
  49.  
  50. _male_ap = [
  51.     (0, 96, 115),
  52.     (1, 101, 112),
  53.     (2, 108, 109),
  54.     (3, 112, 106),
  55.     (4, 118, 103),
  56.     (5, 122, 100),
  57.     (6, 128, 98),
  58.     (7, 134, 96),
  59.     (8, 140, 94),
  60.     (9, 147, 91)]
  61. _update_map(_table, ('male', 'average-pitch'), ' ap %s hs %s ', _male_ap)
  62. _update_map(_table, ('paul', 'average-pitch'), ' ap %s hs %s ', _male_ap)
  63. _man_ap = [
  64.     (0, 50, 125),
  65.     (1, 59, 123),
  66.     (2, 68, 121),
  67.     (3, 77, 120),
  68.     (4, 83, 118),
  69.     (5, 89, 115),
  70.     (6, 95, 112),
  71.     (7, 110, 105),
  72.     (8, 125, 100),
  73.     (9, 140, 95)]
  74. _update_map(_table, ('man', 'average-pitch'), ' ap %s hs %s ', _man_ap)
  75. _update_map(_table, ('harry', 'average-pitch'), ' ap %s hs %s ', _man_ap)
  76. _female_ap = [
  77.     (0, 160, 115),
  78.     (1, 170, 112),
  79.     (2, 181, 109),
  80.     (3, 192, 106),
  81.     (4, 200, 103),
  82.     (5, 208, 100),
  83.     (6, 219, 98),
  84.     (7, 225, 96),
  85.     (8, 240, 94),
  86.     (9, 260, 91)]
  87. _update_map(_table, ('female', 'average-pitch'), ' ap %s hs %s ', _female_ap)
  88. _update_map(_table, ('betty', 'average-pitch'), ' ap %s hs %s ', _female_ap)
  89. _frank_ap = [
  90.     (0, 129, 115),
  91.     (1, 134, 112),
  92.     (2, 141, 109),
  93.     (3, 145, 106),
  94.     (4, 151, 103),
  95.     (5, 155, 100),
  96.     (6, 159, 98),
  97.     (7, 165, 96),
  98.     (8, 171, 94),
  99.     (9, 178, 91)]
  100. _update_map(_table, ('frank', 'average-pitch'), ' ap %s hs %s ', _frank_ap)
  101. _dennis_ap = [
  102.     (0, 84, 115),
  103.     (1, 89, 112),
  104.     (2, 96, 109),
  105.     (3, 100, 106),
  106.     (4, 106, 103),
  107.     (5, 110, 100),
  108.     (6, 116, 98),
  109.     (7, 122, 96),
  110.     (8, 128, 94),
  111.     (9, 135, 91)]
  112. _update_map(_table, ('dennis', 'average-pitch'), ' ap %s hs %s ', _dennis_ap)
  113. _ursula_ap = [
  114.     (0, 196, 115),
  115.     (1, 206, 112),
  116.     (2, 215, 109),
  117.     (3, 224, 106),
  118.     (4, 232, 103),
  119.     (5, 240, 100),
  120.     (6, 251, 98),
  121.     (7, 265, 96),
  122.     (8, 280, 94),
  123.     (9, 300, 91)]
  124. _update_map(_table, ('ursula', 'average-pitch'), ' ap %s hs %s ', _ursula_ap)
  125. _rita_ap = [
  126.     (0, 62, 115),
  127.     (1, 72, 112),
  128.     (2, 81, 109),
  129.     (3, 90, 106),
  130.     (4, 98, 103),
  131.     (5, 106, 100),
  132.     (6, 117, 98),
  133.     (7, 131, 96),
  134.     (8, 146, 94),
  135.     (9, 166, 91)]
  136. _update_map(_table, ('rita', 'average-pitch'), ' ap %s hs %s ', _rita_ap)
  137. _wendy_ap = [
  138.     (0, 156, 115),
  139.     (1, 166, 112),
  140.     (2, 175, 109),
  141.     (3, 184, 106),
  142.     (4, 192, 103),
  143.     (5, 200, 100),
  144.     (6, 211, 100),
  145.     (7, 225, 100),
  146.     (8, 240, 100),
  147.     (9, 260, 100)]
  148. _update_map(_table, ('wendy', 'average-pitch'), ' ap %s hs %s ', _wendy_ap)
  149. _child_ap = [
  150.     (0, 256, 91),
  151.     (1, 266, 89),
  152.     (2, 276, 87),
  153.     (3, 286, 85),
  154.     (4, 296, 83),
  155.     (5, 306, 81),
  156.     (6, 316, 79),
  157.     (7, 326, 77),
  158.     (8, 336, 75),
  159.     (9, 346, 73)]
  160. _update_map(_table, ('child', 'average-pitch'), ' ap %s hs %s ', _child_ap)
  161. _update_map(_table, ('kit', 'average-pitch'), ' ap %s hs %s ', _child_ap)
  162. _male_pr = [
  163.     (0, 0, 0),
  164.     (1, 20, 10),
  165.     (2, 40, 20),
  166.     (3, 60, 30),
  167.     (4, 80, 40),
  168.     (5, 100, 50),
  169.     (6, 137, 60),
  170.     (7, 174, 70),
  171.     (8, 211, 80),
  172.     (9, 250, 100)]
  173. _update_map(_table, ('male', 'pitch-range'), ' pr %s as %s ', _male_pr)
  174. _update_map(_table, ('paul', 'pitch-range'), ' pr %s as %s ', _male_pr)
  175. _update_map(_table, ('frank', 'pitch-range'), ' pr %s as %s ', _male_pr)
  176. _update_map(_table, ('dennis', 'pitch-range'), ' pr %s as %s ', _male_pr)
  177. _man_pr = [
  178.     (0, 0, 0),
  179.     (1, 16, 20),
  180.     (2, 32, 40),
  181.     (3, 48, 60),
  182.     (4, 64, 80),
  183.     (5, 80, 100),
  184.     (6, 137, 100),
  185.     (7, 174, 100),
  186.     (8, 211, 100),
  187.     (9, 250, 100)]
  188. _update_map(_table, ('man', 'pitch-range'), ' pr %s as %s ', _man_pr)
  189. _update_map(_table, ('harry', 'pitch-range'), ' pr %s as %s ', _man_pr)
  190. _female_pr = [
  191.     (0, 0, 0),
  192.     (1, 50, 10),
  193.     (2, 80, 20),
  194.     (3, 100, 25),
  195.     (4, 110, 30),
  196.     (5, 140, 35),
  197.     (6, 165, 57),
  198.     (7, 190, 75),
  199.     (8, 220, 87),
  200.     (9, 250, 100)]
  201. _update_map(_table, ('female', 'pitch-range'), ' pr %s as %s ', _female_pr)
  202. _update_map(_table, ('betty', 'pitch-range'), ' pr %s as %s ', _female_pr)
  203. _update_map(_table, ('ursula', 'pitch-range'), ' pr %s as %s ', _female_pr)
  204. _update_map(_table, ('rita', 'pitch-range'), ' pr %s as %s ', _female_pr)
  205. _update_map(_table, ('wendy', 'pitch-range'), ' pr %s as %s ', _female_pr)
  206. _update_map(_table, ('kit', 'pitch-range'), ' pr %s as %s ', _female_pr)
  207. _update_map(_table, ('child', 'pitch-range'), ' pr %s as %s ', _female_pr)
  208. _male_stress = [
  209.     (0, 0, 0, 0, 0),
  210.     (1, 3, 6, 20, 3),
  211.     (2, 6, 12, 40, 6),
  212.     (3, 9, 18, 60, 9),
  213.     (4, 12, 24, 80, 14),
  214.     (5, 18, 32, 100, 18),
  215.     (6, 34, 50, 100, 20),
  216.     (7, 48, 65, 100, 35),
  217.     (8, 63, 82, 100, 60),
  218.     (9, 80, 90, 100, 40)]
  219. _update_map(_table, ('male', 'stress'), ' hr %s sr %s qu %s bf %s ', _male_stress)
  220. _update_map(_table, ('paul', 'stress'), ' hr %s sr %s qu %s bf %s ', _male_stress)
  221. _update_map(_table, ('frank', 'stress'), ' hr %s sr %s qu %s bf %s ', _male_stress)
  222. _update_map(_table, ('dennis', 'stress'), ' hr %s sr %s qu %s bf %s ', _male_stress)
  223. _man_stress = [
  224.     (0, 0, 0, 0, 0),
  225.     (1, 4, 6, 2, 2),
  226.     (2, 8, 12, 4, 4),
  227.     (3, 12, 18, 6, 6),
  228.     (4, 16, 24, 8, 8),
  229.     (5, 20, 30, 10, 9),
  230.     (6, 40, 48, 32, 16),
  231.     (7, 60, 66, 54, 22),
  232.     (8, 80, 78, 77, 34),
  233.     (9, 100, 100, 100, 40)]
  234. _update_map(_table, ('man', 'stress'), ' hr %s sr %s qu %s bf %s ', _man_stress)
  235. _update_map(_table, ('harry', 'stress'), ' hr %s sr %s qu %s bf %s ', _man_stress)
  236. _female_stress = [
  237.     (0, 1, 1, 0, 0),
  238.     (1, 3, 4, 11, 0),
  239.     (2, 5, 8, 22, 0),
  240.     (3, 8, 12, 33, 0),
  241.     (4, 11, 16, 44, 0),
  242.     (5, 14, 20, 55, 0),
  243.     (6, 35, 40, 65, 10),
  244.     (7, 56, 80, 75, 20),
  245.     (8, 77, 90, 85, 30),
  246.     (9, 100, 100, 100, 40)]
  247. _update_map(_table, ('female', 'stress'), ' hr %s sr %s qu %s bf %s ', _female_stress)
  248. _update_map(_table, ('betty', 'stress'), ' hr %s sr %s qu %s bf %s ', _female_stress)
  249. _update_map(_table, ('ursula', 'stress'), ' hr %s sr %s qu %s bf %s ', _female_stress)
  250. _update_map(_table, ('rita', 'stress'), ' hr %s sr %s qu %s bf %s ', _female_stress)
  251. _update_map(_table, ('wendy', 'stress'), ' hr %s sr %s qu %s bf %s ', _female_stress)
  252. _update_map(_table, ('kit', 'stress'), ' hr %s sr %s qu %s bf %s ', _female_stress)
  253. _update_map(_table, ('child', 'stress'), ' hr %s sr %s qu %s bf %s ', _female_stress)
  254. _male_richness = [
  255.     (0, 0, 100),
  256.     (1, 14, 80),
  257.     (2, 28, 60),
  258.     (3, 42, 40),
  259.     (4, 56, 30),
  260.     (5, 70, 28),
  261.     (6, 60, 24),
  262.     (7, 70, 16),
  263.     (8, 80, 8),
  264.     (9, 100, 0)]
  265. _update_map(_table, ('male', 'richness'), ' ri %s sm %s ', _male_richness)
  266. _update_map(_table, ('paul', 'richness'), ' ri %s sm %s ', _male_richness)
  267. _update_map(_table, ('frank', 'richness'), ' ri %s sm %s ', _male_richness)
  268. _update_map(_table, ('dennis', 'richness'), ' ri %s sm %s ', _male_richness)
  269. _man_richness = [
  270.     (0, 100, 0),
  271.     (1, 96, 3),
  272.     (2, 93, 6),
  273.     (3, 90, 9),
  274.     (4, 88, 11),
  275.     (5, 86, 12),
  276.     (6, 60, 24),
  277.     (7, 40, 44),
  278.     (8, 20, 65),
  279.     (9, 0, 70)]
  280. _update_map(_table, ('man', 'richness'), ' ri %s sm %s ', _man_richness)
  281. _update_map(_table, ('harry', 'richness'), ' ri %s sm %s ', _man_richness)
  282. _female_richness = [
  283.     (0, 0, 100),
  284.     (1, 8, 76),
  285.     (2, 16, 52),
  286.     (3, 24, 28),
  287.     (4, 32, 10),
  288.     (5, 40, 4),
  289.     (6, 50, 3),
  290.     (7, 65, 3),
  291.     (8, 80, 2),
  292.     (9, 100, 0)]
  293. _update_map(_table, ('female', 'richness'), ' ri %s sm %s ', _female_richness)
  294. _update_map(_table, ('betty', 'richness'), ' ri %s sm %s ', _female_richness)
  295. _update_map(_table, ('ursula', 'richness'), ' ri %s sm %s ', _female_richness)
  296. _update_map(_table, ('rita', 'richness'), ' ri %s sm %s ', _female_richness)
  297. _update_map(_table, ('wendy', 'richness'), ' ri %s sm %s ', _female_richness)
  298. _update_map(_table, ('kit', 'richness'), ' ri %s sm %s ', _female_richness)
  299. _update_map(_table, ('child', 'richness'), ' ri %s sm %s ', _female_richness)
  300.  
  301. def getrate(r):
  302.     return int(180 + 4 * r)
  303.  
  304.  
  305. def getvolume(v):
  306.     return int(10 * v)
  307.  
  308.  
  309. def getvoicelist():
  310.     return _table['family'].keys()
  311.  
  312.  
  313. def getvoice(acss):
  314.     '''Memoized function that returns  synthesizer code for
  315.     specified  ACSS setting.
  316.     Synthesizer code is a tupple of the form (open,close)
  317.     where open sets the voice, and close resets it.'''
  318.     name = acss.name()
  319.     if name in _defined_voices:
  320.         return _defined_voices[name]
  321.     _defined_voices[name] = acss2voice(acss)
  322.     return _defined_voices[name]
  323.  
  324.  
  325. def acss2voice(acss):
  326.     '''Return synthesizer code.'''
  327.     code = ''
  328.     familyName = 'male'
  329.     if 'family' in acss:
  330.         familyName = acss['family']['name']
  331.         if familyName in _table['family']:
  332.             code += _table['family'][familyName]
  333.         
  334.     
  335.     if 'rate' in acss:
  336.         code += ' :ra %s' % getrate(acss['rate'])
  337.     
  338.     if 'punctuations' in acss:
  339.         code += ' :punc %s' % acss['punctuations']
  340.     
  341.     if 'gain' in acss:
  342.         code += ' :volume set %s' % getvolume(acss['gain'])
  343.     
  344.     voice = ''
  345.     dv = ''
  346.     for d in [
  347.         'average-pitch',
  348.         'pitch-range',
  349.         'richness',
  350.         'stress']:
  351.         if d in acss:
  352.             if (familyName, d) in _table:
  353.                 voice += _table[(familyName, d)][int(acss[d])]
  354.             
  355.         (familyName, d) in _table
  356.     
  357.     if voice:
  358.         dv = ' :dv %s' % voice
  359.     
  360.     if code or voice:
  361.         code = '[%s  %s]' % (code, dv)
  362.     
  363.     return (code, ' [:np] ')
  364.  
  365.